﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Domain
{
    public partial class Account
    {

        public double Balance
        {
            get
            {
                double? totalDebits = this.Debits.Sum(x => x.Amount);
                double? totalCredits = this.Credits.Sum(x => x.Amount);
                return totalCredits.Value-totalDebits.Value;
            }
        }

        public IList<Transaction> Transactions
        {
            get
            {
                var transactions = new List<Transaction>();
                transactions.AddRange(this.Credits);
                transactions.AddRange(this.Debits);
                transactions.OrderBy(x => x.Date);
                return transactions;
            }
        }

    }
}
